package com.web.base.log.dao;

import org.springframework.stereotype.Repository;
import com.blue.jdbc.BaseDao;
import com.web.base.log.model.Sms;

/**
 * 短信日志数据库访问
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 2017年11月21日
 */
@Repository("logSmsDao")
public class SmsDao extends BaseDao<Sms>
{
	public SmsDao()
	{
	}
	
	@Override
	protected void query(StringBuilder sql, Sms param)
	{
		if (param != null)
		{
			if (param.getUserId() != null && param.getUserId() > 0)
				sql.append(" and a.user_id=:userId");
				
			if (param.getType() != null)
				sql.append(" and a.type=:type");
				
			if (param.getResult() != null)
				sql.append(" and a.result=:result");
				
		}
		sql.append(" order by a.id desc");
	}

	@Override
	protected StringBuilder select()
	{
		StringBuilder sql = new StringBuilder(64);
		sql.append("select a.*, u.name user_name from log_sms a");
		sql.append(" left join uc_user u on u.id=a.user_id");
		sql.append(" where 1=1");
		return sql;
	}
}
